// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vant, { Area } from 'vant/es/index';
import { Popup as VantPopup } from 'vant';
import utils from './common/utils'
import './assets/css/index.scss'
import MintUI, {
  Toast,
  Indicator,
  MessageBox,
  Loadmore,
  InfiniteScroll,
  Actionsheet,
  Popup,
  Range,
  Progress,
  Picker,
  DatetimePicker,
  IndexList,
  IndexSection,
  Header,
  Tabbar,
  TabItem,
  Navbar,
  Button,
  Cell,
  CellSwipe,
  Spinner,
  TabContainer,
  TabContainerItem,
  Search,
  Switch,
  Checklist,
  Radio,
  Field,
  Badge
} from 'mint-ui'
import 'mint-ui/lib/style.css'
import {http} from '@/common/http'
import 'swiper/dist/css/swiper.css'
import 'vant/lib/vant-css/index.css'
import VueAwesomeSwiper from 'vue-awesome-swiper'
require('font-awesome-webpack')

console.log(Vant)

Vue.use(Area, {
  remUnit: 20,
  remPrecision: 8
})
Vue.use(VantPopup)

import SpinLoading from '@/components/SpinLoading.vue';

// Vue.use(DatetimeView)

/* import objectAssign from 'object-assign'
Vue.use(vuexI18n.plugin)
const vuxLocales = require('@/locales/all.yml')
const componentsLocales = require('@/locales/all.yml')
const globalLocales = require('@/locales/all.yml') || {en: {}, 'zh-CN': {}}

const finalLocales = {
  'en': objectAssign(vuxLocales['en'], componentsLocales['en'], globalLocales['en']),
  'zh-CN': objectAssign(vuxLocales['zh-CN'], componentsLocales['zh-CN'], globalLocales['zh-CN'])
}

for (let i in finalLocales) {
  Vue.i18n.add(i, finalLocales[i])
}
Vue.i18n.set('zh-CN') */
Vue.config.productionTip = false
Vue.use(VueAwesomeSwiper)
Vue.use(MintUI)
// Vue.component(Loadmore.name, Loadmore)
// Vue.component(InfiniteScroll.name, InfiniteScroll)
// Vue.component(Actionsheet.name, Actionsheet)
// Vue.component(Popup.name, Popup)
// Vue.component(Range.name, Range)
// Vue.component(Progress.name, Progress)
// Vue.component(DatetimePicker.name, DatetimePicker)
// Vue.component(Picker.name, Picker)
// Vue.component(IndexList.name, IndexList)
// Vue.component(IndexSection.name, IndexSection)
// Vue.component(Header.name, Header)
// Vue.component(Tabbar.name, Tabbar)
// Vue.component(TabItem.name, TabItem)
// Vue.component(Navbar.name, Navbar)
// Vue.component(TabItem.name, TabItem)
// Vue.component(Button.name, Button)
// Vue.component(Cell.name, Cell)
// Vue.component(CellSwipe.name, CellSwipe)
Vue.component(Spinner.name, Spinner)
// Vue.component(TabContainer.name, TabContainer)
// Vue.component(TabContainerItem.name, TabContainerItem)
// Vue.component(Search.name, Search)
// Vue.component(Switch.name, Switch)
// Vue.component(Checklist.name, Checklist)
// Vue.component(Radio.name, Radio)
Vue.component(Field.name, Field)
// Vue.component(Badge.name, Badge)

Vue.prototype.$Utils = {}

for (var key in utils) {
  if (utils.hasOwnProperty(key)) {
    Vue.prototype.$Utils[key] = utils[key]
  }
}

/**
 * 用于控制loading的显示和关闭
 */
Vue.prototype.$Central = new Vue()

Vue.prototype.$Utils.$toast = Toast
Vue.prototype.$Utils.$loading = Indicator
Vue.prototype.$Utils.$message = MessageBox

Vue.filter('toFixed2', function (val) {
  return (val * 1.0).toFixed(2)
})

http.interceptors.request.use(
  config => {
    config.headers['Accept'] = 'application/json'
    if (config.method === 'get') {
      config.params = {
        now: new Date().getTime(),
        ...config.params
      }
      // GET提交的时候防止axios缓存
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// Add a response interceptor handing global errors
// 以后我们有需要再配置 先写在这儿
http.interceptors.response.use(response => response, error => Promise.reject(error))

/* eslint-disable no-new */

new Vue({
  el: '#app',
  components: {
    HomePage: () => import('@/page/HomePage'),
    Products: () => import('@/page/Products'),
    ShoppingTrolley: () => import('@/page/ShoppingTrolley'),
    ProductDetail: () => import('@/page/ProductDetail'),
    Performance: () => import('@/page/performance'),
    SelectAddress: () => import('@/page/SelectAddress'),
    OrderList: () => import('@/page/OrderList'),
    TeamPerformance: () => import('@/page/TeamPerformance'),
    PersonPerformance: () => import('@/page/PersonPerformance'),
    MySelf: () => import('@/page/MySelf'),
    AddNewAddress: () => import('@/page/AddNewAddress.vue'),
    SpinLoading
  }
});

